//
//  DefraySucceedViewController.m
//  KD
//
//  Created by Hubery on 15/8/19.
//  Copyright (c) 2015年 centling. All rights reserved.
//

#import "DefraySucceedViewController.h"
#import <AddressBookUI/AddressBookUI.h>

@interface DefraySucceedViewController ()<ABPeoplePickerNavigationControllerDelegate>
@property (weak, nonatomic) IBOutlet UITextField *phoneNumberText;
@property (weak, nonatomic) IBOutlet UIButton *listBtn;
- (IBAction)listBtnAction:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *sendBtn;
- (IBAction)sendBtnAction:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *succeedLabel;
@property (weak, nonatomic) IBOutlet UIButton *succeedBtn;
- (IBAction)succeedBtnAction:(id)sender;

@end

@implementation DefraySucceedViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.succeedBtn.hidden = YES;
    self.succeedLabel.hidden = YES;
}
+ (instancetype)initWithStoryBoard{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    return [sb instantiateViewControllerWithIdentifier:@"DefraySucceedViewController"];
}
- (IBAction)listBtnAction:(id)sender {
    ABPeoplePickerNavigationController *vc = [[ABPeoplePickerNavigationController alloc] init];
    vc.peoplePickerDelegate = self;
    [self presentViewController:vc animated:YES completion:nil];
}

- (IBAction)sendBtnAction:(id)sender {
    self.sendBtn.hidden = YES;
    self.listBtn.hidden = YES;
    self.phoneNumberText.hidden = YES;
    self.succeedBtn.hidden = NO;
    self.succeedLabel.hidden = NO;

}

- (IBAction)succeedBtnAction:(id)sender {
    UIViewController *vc=[self.navigationController.viewControllers objectAtIndex:1];
    [self.navigationController popToViewController:vc animated:YES];
}

#pragma mark - ABPeoplePickerNavigationControllerDelegate
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
    NSString* lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
    NSString* firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
    if (firstName == nil)firstName = @"";
    if (lastName == nil)lastName = @"";
    //self.name.text = [NSString stringWithFormat:@"%@%@",firstName,lastName];
    // 获取联系人的电话
    // 从联系人中获取到得电话是所有的电话
    ABMultiValueRef phones =   ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFStringRef value =  ABMultiValueCopyValueAtIndex(phones, 0);
    self.phoneNumberText.text = (__bridge NSString *)(value);
    
}

@end
